<gm:page title="Generate Code Pair" authenticate="false">
<style>
.gm-gadget,#gm-signin{
display: none;
}
</style>

  <!--
    This generate code pair for Employee Survey and Co-worker Survey
    using the current time.
    @author: Andrew WAT
  -->

<script>

function getHex(dec) {
var hexArray = new Array( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" );
var code1 = Math.floor(dec / 16);
var code2 = dec - code1 * 16;
var decToHex = hexArray[code2];
return (decToHex);
}

function toHexCode(dec) {
var hexCode= new Array();
var i=0;
while(dec > 15) {
hexCode[i] = getHex(dec);
dec = Math.floor(dec / 16);
i+=1;
}
hexCode[i] = getHex(dec);
var decToHex = "";
for(i=hexCode.length-1; i>=0; i--) {
    decToHex += hexCode[i]; 
}
return decToHex;
}

var dd = new Date;
var ss = new Date('1-1-2008');
var ee = new Date('5-17-2010');

// document.write(dd, "@@@", ss ,"###", ee, "<br>");

var d = dd.getTime();
var s = ss.getTime();
var e = ee.getTime();

// document.write(d, "@@@", s ,"###", e, "<br>");

var c = Math.round((d - s)/100);
var code = toHexCode(c);
var cw = Math.round((e - d)/100);
var coworker = toHexCode(cw);

// document.write(c, "@@@", cw ,"<br>");
document.write('Please use <b>', code, '</b> for the CODE in the <a href="http://spreadsheets.google.com/viewform?key=pJP5Sg7Y-NQfvM2JzkKABQQ&hl=en" target="_blank">Employee Opinion Survey</a>.<p>Please copy and forward the following to your co-worker<br>Please read <a href="http://sites.google.com/site/watandrew/Home/research/information-sheet-to-the-co-worker-of-the-research-participant" target="_blank">Information sheet to the co-worker of the research participant</a> and use <b>', coworker, '</b> for the CODE in the Colleague Opinion Survey<p>');

document.write('If the code is displayed as <b>undefined</b>, there is problem with Google mashup engine which has happened a couple of times before. Please be patient and try to access the page after a while.');

</script>
</gm:page>
